package com.xijing.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.xijing.model.ProduceInfo;
import com.xijing.model.RoomType;
import com.xijing.model.SYS_User;

public class RoomTypeDAO  extends BaseDAO {
	private String columnFiel = "SRT_ID,SRT_Name,SRT_Remark";
	/**
	 * 查询获取一个对象列表
	 * @return
	 */
	public List<RoomType> getRoomTypeList(String KeyStr) {
		Connection conn = getConnection();
		QueryRunner qr = new QueryRunner();
		String sql = "SELECT " + columnFiel + " FROM SYS_RoomType where SRT_Name like '%"+KeyStr+"%' ";
		try {
			List<RoomType> list = qr.query(conn, sql, new BeanListHandler<RoomType>(RoomType.class));
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public int insertRoomType(RoomType Room) {
		Connection conn = getConnection();
		QueryRunner qr = new QueryRunner();
		String sql = "insert into SYS_RoomType ("+columnFiel+")"
					+ " values"
					+ " (?, ?, ?)";
		try {
			int count = qr.update(conn, sql, 
					Room.getSRT_ID(), 
					Room.getSRT_Name(), 
					Room.getSRT_Remark()
					);
			
			return count;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return 0;
	}
	
	
	public RoomType getRoomType(String ID) {
		Connection conn = getConnection();
		QueryRunner qr = new QueryRunner();
		String sql = "SELECT " + columnFiel + " FROM SYS_RoomType where SRT_ID=? ";
		try {
			RoomType room = qr.query(conn, sql, new BeanHandler<RoomType>(RoomType.class), ID);
			return room;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public int updateRoomType(RoomType Room) {
		Connection conn = getConnection();
		QueryRunner qr = new QueryRunner();
		String sql = "update SYS_RoomType set SRT_Name = '"+Room.getSRT_Name()+"',SRT_Remark = '"+Room.getSRT_Remark()+"' where SRT_ID = '"+Room.getSRT_ID()+"'";
		try {
			int count = qr.update(conn, sql);
			return count;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return 0;
	}
}
